package org.ting.book.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.ting.book.interceptor.LoginInterceptor;

/**
 * 注册拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //注册自定义拦截对象
        registry.addInterceptor(loginInterceptor)
                //设置拦截器生效路径
                .addPathPatterns("/user/*")
                .addPathPatterns("/book/*")
                .addPathPatterns("/borrow/*")
                //排除路径
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/signUp")
                .excludePathPatterns("/user/rest");
    }
}
